package com.oim.core.business.controller;

import com.oim.core.app.AppContext;
import com.oim.core.bean.UserData;
import com.oim.core.business.manage.RemoteManage;
import com.oim.core.business.sender.RemoteSender;
import com.oim.core.business.sender.UserSender;
import com.oim.core.common.app.controller.BaseController;
import com.oim.core.common.box.PersonalBox;
import com.oim.core.common.box.UserDataBox;
import com.oim.core.common.box.UserDataTempBox;
import com.oim.core.net.server.Back;
import com.only.general.annotation.parameter.Define;
import com.only.net.data.action.DataBackAction;
import com.only.net.data.action.DataBackActionAdapter;

public class RemoteController extends BaseController {

	public RemoteController(AppContext appContext) {
		super(appContext);
	}

	public void requestRemoteControl(UserData userData) {

		RemoteManage rm = this.appContext.getManage(RemoteManage.class);
		rm.showRequestRemoteControlFrame(userData);

		UserData sendUser = PersonalBox.get(UserData.class);

		RemoteSender rs = this.appContext.getSender(RemoteSender.class);
		rs.requestRemoteControl(sendUser.getId(), userData.getId());
	}

	public void requestRemoteControl(String userId) {

		UserData userData = UserDataBox.get(userId);// 先从好友集合里面获取用户信息，如果用户不是好友，那么从服务器下载用户信息
		if (null == userData) {// 为null说明发送信息的不在好友列表，那么就要从服务器获取发送信息用户的信息了
			DataBackAction dataBackAction = new DataBackActionAdapter() {
				@Back
				public void back(@Define("userData") UserData userData) {
					UserDataTempBox.put(userData.getId(), userData);
					requestRemoteControl(userData);
				}
			};
			UserSender uh = this.appContext.getSender(UserSender.class);
			uh.getUserDataById(userId, dataBackAction);
		} else {
			requestRemoteControl(userData);
		}
	}
}
